/*
 *      Author:	Wolter Hellmund
 *      Email:	wolterh6@gmail.com
 *      --------------------------------------
 *      Record source code
 *      --------------------------------------
 *      Copyright 2009. All Rights Reserved.
 */

#include "record.hpp"

Record::Record()
{
	// Report in!
	handy_msgbox(H_REPORT,"Record initialized");
	// Load the record when created
	load();
}

Record::~Record() {;} // Kept for possible later usage

void Record::load()
{
	// Create the file buffer
	ifstream file(RECORD_DATA_FILE);
	// Create the temporal storage variables
	string line;
	vector<string> vec_split;
	// Parse the file
	while( getline(file,line) )
	{
		// Split and add to vectors
		unsigned int splitpnt = line.find("\\",0);
		vec_stns.push_back( line.substr(0, splitpnt) );
		vec_urls.push_back( line.substr((splitpnt+1), line.size()) );
	}
	// Close file
	file.close();
	// Test
	for (int i = 0; i < vec_stns.size(); i++)
		cout << '\t' << vec_stns[i] << " : " << vec_urls[i] <<endl;
	// Report success
	handy_msgbox(H_REPORT,"Record loaded successfully");
	// Exit
	return;
}

void Record::save()
{
	// Create file object
	ofstream file(RECORD_DATA_FILE);
	// Write data to file
	for (int i = 0; i < vec_stns.size(); i++) // vec_urls could be used as well as delimiter
	{
		file << vec_stns[i] << "\\" << vec_urls[i] << endl;
	}
	// Close file
	file.close();
	// Report success
	handy_msgbox(H_REPORT,"Record successfully saved");
	// Exit
	return;
}
